// ----------------------------------------
// Filename: main.c
// Description: the unit testing of the scheduler
// Author: Jon Maloney
// Date: 8-Jun-2012
//

//************************************************************
//                    Include .h files
//************************************************************
#include "Context_Switch_Test.h"
#include "thread.h"
#include "Scheduler.h"
#include <stdio.h>
//************************************************************
//                    Include external references
//************************************************************

//************************************************************
//                    Define Statements
//************************************************************

//************************************************************
//                    Struct, Union, enum Statements
//************************************************************

//************************************************************
//                    Global variables and constants
//************************************************************

//************************************************************
//                    Prototype Private Functions
//************************************************************

void taskA(void * functionArgument);
void taskB(void * functionArgument);

//************************************************************
//                    Implementation
//************************************************************


//************************************************************
//                    Test Description
//
//	Test 1. In main.c Call Context switch Test. 
//	
//
//************************************************************

void contextSwitchTest(char testCase)
{
	switch (testCase)
	{
		case 1:
			Thread_Create(taskA, 'A', 200, 1);
			Thread_Create(taskA, 'B', 200, 1);
			Thread_Create(taskA, 'C', 200, 1);
			Thread_Create(taskA, 'D', 200, 1);
			break;
		case 2:
			Thread_Create(taskA, 'A', 200, 1);
			Thread_Create(taskA, 'B', 200, 2);
			Thread_Create(taskA, 'C', 200, 3);
			Thread_Create(taskA, 'D', 200, 4);
			break;
		case 3:
			Thread_Create(taskA, 'A', 200, 4);
			Thread_Create(taskA, 'B', 200, 3);
			Thread_Create(taskA, 'C', 200, 2);
			Thread_Create(taskA, 'D', 200, 1);
			break;
		case 4:
			Thread_Create(taskA, 'D', 200, 1);
			Thread_Create(taskA, 'C', 200, 1);
			Thread_Create(taskA, 'B', 200, 1);
			Thread_Create(taskA, 'A', 200, 1);
			break;
		case 5:
			Thread_Create(taskB, 10, 200, 4);
			Thread_Create(taskB, 20, 200, 3);
			Thread_Create(taskB, 30, 200, 2);
			Thread_Create(taskB, 40, 200, 1);
			break;
		case 6:
			Thread_Create(taskB, 1000, 200, 1);
			Thread_Create(taskB, 2000, 200, 1);
			Thread_Create(taskB, 4000, 200, 1);
			Thread_Create(taskB, 8000, 200, 1);
	}
	
}

void taskA(void * functionArgument)
{
	char taskName = (char)functionArgument;
	while(1)
	{
		printf("Task %c is running\n", taskName);
		Scheduler_Delay(1000);//Delay for 1 s
	}
}


void taskB(void * functionArgument)
{
	UINT16 delayTime = (UINT16)functionArgument;
	while(1)
	{
		///printf("\n Tick value = %d\n", Scheduler_GetTickCount());
		printf("\nTask is to sleep for %d\n", delayTime);
		Scheduler_Delay(delayTime);
	}
}
